﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using XYAC.Framework.MonitorTireMaterialOnline.Entities;
using XYAC.Framework.MonitorTireMaterialOnline.Extensions;

namespace XYAC.Framework.MonitorTireMaterialOnline.Context
{
    public partial class CustomHisDataContext : HisDataContext
    {

        public CustomHisDataContext(IOptionsMonitor<AppConfig> appData, DateOnly date)
        {
            AppConfig = appData;


            Date = date;
        }


        //public virtual DbSet<SpecValTable> SpecVal { get; set; } = null!;
        public IOptionsMonitor<AppConfig> AppConfig { get; }
        public DateOnly Date { get; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {


            // 配置 SQL Server 数据库连接字符串
            //optionsBuilder.UseJet(AppConfig?.CurrentValue?.AccessCAreaHisConnectionString);
            if (!optionsBuilder.IsConfigured)
            {

                optionsBuilder.UseJet(AppConfig?.CurrentValue?.AccessCAreaHisConnectionString.Replace("{DateNow}", Date.ToString("yyyy-MM-dd")));

            }
        }


    }
}
